package com.ruoyi.web.controller.schedulemission;

import com.ruoyi.info.domain.VinfoCar;
import com.ruoyi.info.domain.VinfoCountOrder;
import com.ruoyi.info.domain.vo.MyPoint;
import com.ruoyi.info.mapper.VinfoCarMapper;
import com.ruoyi.info.service.IVinfoCarService;
import com.ruoyi.info.service.IVinfoCountOrderService;
import com.ruoyi.wx.domain.VehiclesLog;
import com.ruoyi.wx.mapper.VehiclesLogMapper;
import com.ruoyi.wx.service.IVehiclesLogService;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicReference;

@Component
public class ScheduleMission {

    @Resource
    private IVehiclesLogService iVehiclesLogService;

    @Resource
    private IVinfoCarService carService;

    @Resource
    private VinfoCarMapper carMapper;

    @Resource
    private VehiclesLogMapper vehiclesLogMapper;

    @Resource
    private IVinfoCountOrderService vinfoCountOrderService;

    @Resource
    private ThreadPoolTaskExecutor threadPoolTaskExecutor;

    public static ScheduleMission scheduleMission;

    @PostConstruct
    public void init(){
        scheduleMission = this;
        scheduleMission.carService = this.carService;
        scheduleMission.iVehiclesLogService = this.iVehiclesLogService;
        scheduleMission.vinfoCountOrderService = this.vinfoCountOrderService;
        scheduleMission.carMapper = this.carMapper;
        threadPoolTaskExecutor = this.threadPoolTaskExecutor;
    }

//    public static void storageOrder() throws ParseException {
//        Date date = new Date();
//        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
//        Date earliestDate = scheduleMission.iVehiclesLogService.selectEarliestDate();
//        String earliestDatestr = simpleDateFormat.format(earliestDate);
//        Long timestamp = simpleDateFormat.parse(earliestDatestr).getTime();
//        DecimalFormat decimalFormat = new DecimalFormat("0.0");
//        List<VinfoCar> list = scheduleMission.carMapper.selectVinfoCarList(new VinfoCar(),null);
//        CountDownLatch countDownLatch = new CountDownLatch(list.size());
//        for (int j = 0; j < list.size(); j++) {
//            int finalJ = j;
//            VinfoCar finalCar = list.get(finalJ);
//            Long finalTimestamp = timestamp;
//            scheduleMission.threadPoolTaskExecutor.execute(()->{
//                List<VinfoCountOrder> vinfoCountOrderList = new ArrayList<>();
////                VinfoCar car = list.get(finalJ);
//                VinfoCar car = finalCar;
//                double initWeight = car.getIniweight();
//                Date beginTime = new Date(finalTimestamp);
//                Date endTime = new Date(beginTime.getTime()+1000L*60*60*24);
//                while (endTime.getTime() < date.getTime()) {
//                    List<VehiclesLog> vehiclesLogList = scheduleMission.vehiclesLogMapper.selectToCountWeight(car.getCarNo(), beginTime, endTime);
//                    List<Map<String, Object>> weightList = new ArrayList<>();
//                    List<Map<String, Object>> weightPeakList = new ArrayList<>();
//                    List<Map<String, Object>> weightTroughList = new ArrayList<>();
//                    for (VehiclesLog vehiclesLog : vehiclesLogList) {
//                        String eventDesc = vehiclesLog.getEventDesc();
//                        if (eventDesc.contains("AD0")) {
//                            String weightstr = vehiclesLog.getEventDesc().substring(eventDesc.indexOf("AD0") + 4, eventDesc.indexOf("AD1") - 1);
//                            Double weight = Double.parseDouble(weightstr);
//                            Map<String, Object> map = new HashMap<>();
//                            map.put("gpstime", vehiclesLog.getGpsTime());
//                            map.put("weight", weight);
//                            map.put("mileage", vehiclesLog.getMileage());
//                            weightList.add(map);
//                        }
//                    }
//                    for (int i = 0; i < weightList.size(); i++) {
//                        double weight1 = Double.parseDouble(weightList.get(i).get("weight").toString());
//                        double weight2;
//                        double weight3;
//                        if (i == 0) {
//                            if ( i+1 < weightList.size()) {
//                                weight3 = Double.parseDouble(weightList.get(i + 1).get("weight").toString());
////                                if (weight1 > weight3 && weight1 - initWeight > 200) {
//                                if (weight1 > weight3 && weight1 > (initWeight + 200)) {
////                                    weightList.get(i).put("weight", weight1);
//                                    weightPeakList.add(weightList.get(i));
//                                }
//                            }
//                        } else if (i == weightList.size() - 1) {
//                            if (weightPeakList.size()>weightTroughList.size()) {
//                                weight2 = Double.parseDouble(weightList.get(i - 1).get("weight").toString());
////                              if (weight1 < weight2 && weight1 - initWeight < 200) {
//                                if (weight1 < weight2) {
//                                    if (weightTroughList.size() < weightPeakList.size() && ((Double) weightPeakList.get(weightPeakList.size() - 1).get("weight") > weight1 && weight1 < (initWeight+200))) {
//                                        weightTroughList.add(weightList.get(i));
//                                    } else {
//                                        weightPeakList.remove(weightPeakList.size() - 1);
//                                    }
//                                }
//                            }
//                        } else {
//                            weight2 = Double.parseDouble(weightList.get(i - 1).get("weight").toString());
//                            weight3 = Double.parseDouble(weightList.get(i + 1).get("weight").toString());
////                            if (weight1 > weight2 && weight1 > weight3 && weight1 - initWeight > 200) {
//                            if (weightPeakList.size() == weightTroughList.size()) {
//                                if (weight1 > weight2 && weight1 >= weight3 && weight1 > (initWeight+200)) {
////                                        weightList.get(i).put("weight", weight1);
//                                    if (weightPeakList.size() > 0) {
//                                        if (((Double) weightTroughList.get(weightTroughList.size() - 1).get("weight") < weight1)) {
//                                            weightPeakList.add(weightList.get(i));
//                                        }
//                                    }
//                                }
//                            }
////                            if (weight2 > weight1 && weight3 > weight1 && weight1 - initWeight < 200) {
//                            if (weightTroughList.size() < weightPeakList.size()) {
//                                if (weight2 > weight1 && weight3 >= weight1) {
//                                    if ((((Date)(weightList.get(i).get("gpstime"))).getTime() - ((Date)weightPeakList.get(weightPeakList.size()-1).get("gpstime")).getTime() > 3000000) && ((Double)weightPeakList.get(weightPeakList.size()-1).get("weight") > weight1)) {
//                                        weightTroughList.add(weightList.get(i));
//                                    }
//                                }
//                            }
//                        }
//                    }
//                    for (int i = 0; i < weightPeakList.size() && i < weightTroughList.size(); i++) {
//                        VinfoCountOrder vinfoCountOrder = new VinfoCountOrder();
//                        vinfoCountOrder.setBeginTime((Date) (weightPeakList.get(i).get("gpstime")));
//                        vinfoCountOrder.setEndTime((Date) (weightTroughList.get(i).get("gpstime")));
//                        vinfoCountOrder.setCarNo(car.getCarNo());
//                        vinfoCountOrder.setWeight(Double.parseDouble(weightPeakList.get(i).get("weight").toString())-Double.parseDouble(weightTroughList.get(i).get("weight").toString()));
//                        vinfoCountOrder.setCreateTime(date);
//                        vinfoCountOrder.setSerial(i);
//                        vinfoCountOrder.setDriverName(car.getDriverName());
//                        vinfoCountOrder.setCompName(car.getCompName());
//                        vinfoCountOrder.setDrivingDuration(Double.parseDouble(decimalFormat.format((vinfoCountOrder.getEndTime().getTime() - vinfoCountOrder.getBeginTime().getTime()) / 1000.0 / 60 / 60)));
//                        if (weightPeakList.get(i).get("mileage") != null) {
//                            vinfoCountOrder.setStartMileage(Integer.parseInt(weightPeakList.get(i).get("mileage").toString()));
//                        }
//                        if (weightTroughList.get(i).get("mileage") != null) {
//                            vinfoCountOrder.setEndMileage(Integer.parseInt(weightTroughList.get(i).get("mileage").toString()));
//                        }
//                        if (weightPeakList.get(i).get("mileage") != null && weightTroughList.get(i).get("mileage") != null) {
//                            vinfoCountOrder.setMileage(vinfoCountOrder.getEndMileage() - vinfoCountOrder.getStartMileage());
//                        }
//                        if (vinfoCountOrder.getStartMileage() != null && vinfoCountOrder.getEndMileage() != null) {
//                            if (vinfoCountOrder.getStartMileage().equals(vinfoCountOrder.getEndMileage())) {
//                                continue;
//                            }
//                        }
//                        vinfoCountOrderList.add(vinfoCountOrder);
//                    }
//                    beginTime = endTime;
//                    endTime = new Date(beginTime.getTime() + 1000L * 60 * 60 * 24);
//                }
//                System.out.println("======"+vinfoCountOrderList);
//                if (vinfoCountOrderList.size() > 0) {
//                    System.out.println("删除原记录");
//                    scheduleMission.vinfoCountOrderService.delete(earliestDate,date,vinfoCountOrderList.get(0).getCarNo());
//                    System.out.println("插入新纪录");
//                    scheduleMission.vinfoCountOrderService.insert(vinfoCountOrderList);
//                }
//                countDownLatch.countDown();
//            });
//        }
//        try {
//            countDownLatch.await();
//            System.out.println("任务完成");
//        } catch (InterruptedException e) {
//            e.printStackTrace();
//        }
//    }


//    @Scheduled(cron = "0 0 0/1 * * ?")
//    public void storageOrderCurrentDay() throws ParseException {
//        Date date = new Date();
//        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
//        DecimalFormat decimalFormat = new DecimalFormat("0.0");
//        List<VinfoCar> list = scheduleMission.carMapper.selectVinfoCarList(new VinfoCar(),null);
//        CountDownLatch countDownLatch = new CountDownLatch(list.size());
//        Date beginTime = simpleDateFormat.parse(simpleDateFormat.format(new Date(date.getTime()-1)));
//        Date endTime = new Date(beginTime.getTime()+1000L*60*60*24);
//        for (int j = 0; j < list.size(); j++) {
//            int finalJ = j;
//            scheduleMission.threadPoolTaskExecutor.execute(()->{
//                List<VinfoCountOrder> vinfoCountOrderList = new ArrayList<>();
//                VinfoCar car = list.get(finalJ);
//                double initWeight = car.getIniweight();
//                List<VehiclesLog> vehiclesLogList = scheduleMission.vehiclesLogMapper.selectToCountWeight(car.getCarNo(), beginTime, endTime);
//                List<Map<String, Object>> weightList = new ArrayList<>();
//                List<Map<String, Object>> weightPeakList = new ArrayList<>();
//                List<Map<String, Object>> weightTroughList = new ArrayList<>();
//                for (VehiclesLog vehiclesLog : vehiclesLogList) {
//                    String eventDesc = vehiclesLog.getEventDesc();
//                    if (eventDesc.contains("AD0")) {
//                        String weightstr = vehiclesLog.getEventDesc().substring(eventDesc.indexOf("AD0") + 4, eventDesc.indexOf("AD1") - 1);
//                        Double weight = Double.parseDouble(weightstr);
//                        Map<String, Object> map = new HashMap<>();
//                        map.put("gpstime", vehiclesLog.getGpsTime());
//                        map.put("weight", weight);
//                        map.put("mileage", vehiclesLog.getMileage());
//                        weightList.add(map);
//                    }
//                }
//                for (int i = 0; i < weightList.size(); i++) {
//                    double weight1 = Double.parseDouble(weightList.get(i).get("weight").toString());
//                    double weight2;
//                    double weight3;
//                    if (i == 0) {
//                        if ( i+1 < weightList.size()) {
//                            weight3 = Double.parseDouble(weightList.get(i + 1).get("weight").toString());
//                            if (weight1 > weight3 && weight1 - initWeight > 200) {
//                                weightList.get(i).put("weight", weight1 - initWeight + 1000);
//                                weightPeakList.add(weightList.get(i));
//                            }
//                        }
//                    } else if (i == weightList.size() - 1) {
//                        if (i-1 >= 0) {
//                            weight2 = Double.parseDouble(weightList.get(i - 1).get("weight").toString());
//                            if (weight1 < weight2 && weight1 - initWeight < 200) {
//                                if (weightTroughList.size() < weightPeakList.size()) {
//                                    weightTroughList.add(weightList.get(i));
//                                }
//                            }
//                        }
//                    } else {
//                        weight2 = Double.parseDouble(weightList.get(i - 1).get("weight").toString());
//                        weight3 = Double.parseDouble(weightList.get(i + 1).get("weight").toString());
//                        if (weight1 > weight2 && weight1 > weight3 && weight1 - initWeight > 200) {
//                            if (weightPeakList.size() == weightTroughList.size()) {
//                                weightList.get(i).put("weight", weight1 - initWeight + 1000);
//                                weightPeakList.add(weightList.get(i));
//                            }
//                        }
//                        if (weight2 > weight1 && weight3 > weight1 && weight1 - initWeight < 200) {
//                            if (weightTroughList.size() < weightPeakList.size()) {
//                                weightTroughList.add(weightList.get(i));
//                            }
//                        }
//                    }
//                }
//                for (int i = 0; i < weightPeakList.size() && i < weightTroughList.size(); i++) {
//                    VinfoCountOrder vinfoCountOrder = new VinfoCountOrder();
//                    vinfoCountOrder.setBeginTime((Date) (weightPeakList.get(i).get("gpstime")));
//                    vinfoCountOrder.setEndTime((Date) (weightTroughList.get(i).get("gpstime")));
//                    vinfoCountOrder.setCarNo(car.getCarNo());
//                    vinfoCountOrder.setWeight(Double.parseDouble(weightPeakList.get(i).get("weight").toString()));
//                    vinfoCountOrder.setCreateTime(date);
//                    vinfoCountOrder.setSerial(i);
//                    vinfoCountOrder.setDriverName(car.getDriverName());
//                    vinfoCountOrder.setCompName(car.getCompName());
//                    vinfoCountOrder.setDrivingDuration(Double.parseDouble(decimalFormat.format((vinfoCountOrder.getEndTime().getTime() - vinfoCountOrder.getBeginTime().getTime()) / 1000.0 / 60 / 60)));
//                    if (weightPeakList.get(i).get("mileage") != null) {
//                        vinfoCountOrder.setStartMileage(Integer.parseInt(weightPeakList.get(i).get("mileage").toString()));
//                    }
//                    if (weightTroughList.get(i).get("mileage") != null) {
//                        vinfoCountOrder.setEndMileage(Integer.parseInt(weightTroughList.get(i).get("mileage").toString()));
//                    }
//                    if (weightPeakList.get(i).get("mileage") != null && weightTroughList.get(i).get("mileage") != null) {
//                        vinfoCountOrder.setMileage(vinfoCountOrder.getEndMileage() - vinfoCountOrder.getStartMileage());
//                    }
//                    if (vinfoCountOrder.getStartMileage()-vinfoCountOrder.getEndMileage()<500){
//                        continue;
//                    }
//                    vinfoCountOrderList.add(vinfoCountOrder);
//                }
//
//                System.out.println("======"+vinfoCountOrderList);
//                if (vinfoCountOrderList.size() > 0) {
//                    System.out.println("删除原记录");
//                    scheduleMission.vinfoCountOrderService.delete(beginTime,endTime,vinfoCountOrderList.get(0).getCarNo());
//                    System.out.println("插入新纪录");
//                    scheduleMission.vinfoCountOrderService.insert(vinfoCountOrderList);
//                }
//                countDownLatch.countDown();
//            });
//        }
//        try {
//            countDownLatch.await();
//            System.out.println("任务完成");
//        } catch (InterruptedException e) {
//            e.printStackTrace();
//        }
//    }




    //统计订单
    public static void countOrder() throws ParseException {
        //结束时间date默认当前时间
        Date date = new Date();//1691280000000L
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        Date earliestDate = scheduleMission.iVehiclesLogService.selectEarliestDate();
        //开始时间默认第一条日志的创建时间
        String earliestDatestr = simpleDateFormat.format(earliestDate);
        Long timestamp = simpleDateFormat.parse(earliestDatestr).getTime();
//        timestamp = 1693526400000L;//9月1号
        //查询车辆信息列表
        List<VinfoCar> list = scheduleMission.carMapper.selectVinfoCarList(new VinfoCar(),null);
        //线程计数
        CountDownLatch countDownLatch = new CountDownLatch(list.size());

        for (int j = 0; j < list.size(); j++) {
            int finalJ = j;
            VinfoCar finalCar = list.get(finalJ);
            Long finalTimestamp = timestamp;
            //基于每个车牌创建线程
            scheduleMission.threadPoolTaskExecutor.execute(()->{
                List<VinfoCountOrder> vinfoCountOrderList = new ArrayList<>();
                VinfoCar car = finalCar;
                //当天0点0分0秒
                Date beginTime = new Date(finalTimestamp);
                //下一天0点
                Date endTime = new Date(beginTime.getTime()+1000L*60*60*24);
                while (endTime.getTime() < date.getTime()) {
                    List<VehiclesLog> vehiclesLogList = scheduleMission.iVehiclesLogService.selectByCarNoAndDateRange(car.getDeviceNo(),car.getCarNo(),beginTime,endTime);
                    vinfoCountOrderList = geneCountOrderList(vehiclesLogList,car);

                    //删除原记录
                    System.out.println("==删除=="+car.getCarNo()+"=="+simpleDateFormat.format(beginTime)+"数据");
                    scheduleMission.vinfoCountOrderService.delete(beginTime,endTime,car.getCarNo());
                    if (vinfoCountOrderList.size()>0) {
                        //插入新记录
                        System.out.println("==插入=="+car.getCarNo()+"=="+simpleDateFormat.format(beginTime)+"数据");
                        scheduleMission.vinfoCountOrderService.insert(vinfoCountOrderList);
                    }

                    beginTime = endTime;
                    endTime = new Date(beginTime.getTime() + 1000L * 60 * 60 * 24);
                }
                countDownLatch.countDown();
            });
        }
        try {
            countDownLatch.await();
            System.out.println("计算完成");
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }


    @Scheduled(cron = "0 0 0/1 * * ?")
    public static void countCurrentDayOrder() throws ParseException {
        //结束时间date默认当前时间
        Date date = new Date();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        //开始时间默认当天0点
        String earliestDatestr = simpleDateFormat.format(date);
        Long timestamp = simpleDateFormat.parse(earliestDatestr).getTime()-1;
        //查询车辆信息列表
        List<VinfoCar> list = scheduleMission.carMapper.selectVinfoCarList(new VinfoCar(),null);
        //线程计数
        CountDownLatch countDownLatch = new CountDownLatch(list.size());

        for (int j = 0; j < list.size(); j++) {
            VinfoCar finalCar = list.get(j);
            Long finalTimestamp = timestamp;
            //基于每个车牌创建线程
            scheduleMission.threadPoolTaskExecutor.execute(()->{
                List<VinfoCountOrder> vinfoCountOrderList = new ArrayList<>();
                VinfoCar car = finalCar;
                //当天0点0分0秒
                Date beginTime = new Date(finalTimestamp);
                //下一天0点
                Date endTime = new Date(beginTime.getTime()+1000L*60*60*24);

                List<VehiclesLog> vehiclesLogList = scheduleMission.iVehiclesLogService.selectByCarNoAndDateRange(car.getDeviceNo(),car.getCarNo(),beginTime,endTime);
                vinfoCountOrderList = geneCountOrderList(vehiclesLogList,car);
                //删除原记录
                System.out.println("==删除=="+car.getCarNo()+"=="+simpleDateFormat.format(beginTime)+"数据");
                scheduleMission.vinfoCountOrderService.delete(beginTime,endTime,car.getCarNo());
                if (!vinfoCountOrderList.isEmpty()) {
                    //插入新记录
                    System.out.println("==插入=="+car.getCarNo()+"=="+simpleDateFormat.format(beginTime)+"数据");
                    scheduleMission.vinfoCountOrderService.insert(vinfoCountOrderList);
                }
                //减少CountDownLatch对象的计数器值。当计数器值到达0时，所有因调用await方法而等待的线程将被唤醒并继续执行。
                countDownLatch.countDown();
            });
        }
        try {
            countDownLatch.await();
            System.out.println("计算完成");
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    private static void setMyPoint(VehiclesLog vehiclesLog,MyPoint myPoint){
        String eventDesc = vehiclesLog.getEventDesc();
        double weight = Double.parseDouble(eventDesc.substring(eventDesc.indexOf("AD0")+4,eventDesc.indexOf("AD1")-1));
        myPoint.setWeight(weight);
        myPoint.setSpeed(vehiclesLog.getSpeed().intValue());
        myPoint.setMileage(vehiclesLog.getMileage().intValue());
        myPoint.setTime(vehiclesLog.getGpsTime());
    }

    public static void geneCountOrder(VinfoCar car,int serial, VinfoCountOrder vinfoCountOrder, MyPoint maxPoint, MyPoint minPoint){
        DecimalFormat decimalFormat = new DecimalFormat("0.0");
        vinfoCountOrder.setBeginTime(maxPoint.getTime());
        vinfoCountOrder.setEndTime(minPoint.getTime());
        vinfoCountOrder.setCarNo(car.getCarNo());
        if (car.getLimitweight() > 10 && maxPoint.getWeight() > 9500){
            vinfoCountOrder.setWeight(maxPoint.getWeight() + (car.getLimitweight()-10)*1000);
        }else {
            vinfoCountOrder.setWeight(maxPoint.getWeight()  + car.getIniweight());
        }
        vinfoCountOrder.setCreateTime(new Date());
        vinfoCountOrder.setSerial(serial);
        vinfoCountOrder.setDriverName(car.getDriverName());
        vinfoCountOrder.setCompName(car.getCompName());
        vinfoCountOrder.setStartMileage(maxPoint.getMileage());
        vinfoCountOrder.setEndMileage(minPoint.getMileage());
        vinfoCountOrder.setMileage(minPoint.getMileage()- maxPoint.getMileage());
        vinfoCountOrder.setDrivingDuration(Double.parseDouble(decimalFormat.format((minPoint.getTime().getTime()-maxPoint.getTime().getTime())/1000.0/60/60)));

    }

    /**
     * 实时状态（0-未上线，1-离线，2-停车，3-行驶，4-停留，5-维修）
     */

    private static List<VinfoCountOrder> geneCountOrderList(List<VehiclesLog> vehiclesLogList,VinfoCar car){
        double initWeight = car.getIniweight();
        List<VinfoCountOrder> vinfoCountOrderList = new ArrayList<>();
        List<MyPoint> maxPointList = new ArrayList<>();
        List<MyPoint> minPointList= new ArrayList<>();

        for (int i = 0; i < vehiclesLogList.size()-1; i++) {
            VehiclesLog log = vehiclesLogList.get(i);
            String eventDesc = log.getEventDesc();
            double weight = Double.parseDouble(eventDesc.substring(eventDesc.indexOf("AD0")+4,eventDesc.indexOf("AD1")-1));

            if (i == 0){
                MyPoint maxPoint = new MyPoint();
                setMyPoint(log,maxPoint);
                maxPointList.add(maxPoint);
                continue;
            }

            //更新最大值
            if (weight > maxPointList.get(maxPointList.size()-1).getWeight()) {
                if (maxPointList.size() > minPointList.size()) {
                    MyPoint maxPoint = maxPointList.get(maxPointList.size() - 1);
                    maxPoint.setWeight(weight);
                    continue;
                }
            }

            //插入最大值
            if (maxPointList.size() == minPointList.size()) {
                if (weight > minPointList.get(minPointList.size() - 1).getWeight() + 1000) {
                    MyPoint maxPoint = new MyPoint();
                    setMyPoint(log, maxPoint);
                    maxPointList.add(maxPoint);
                    continue;
                }
            }

            if (minPointList.size() < maxPointList.size()) {
                if (weight + 1000 < maxPointList.get(maxPointList.size() - 1).getWeight()) {
                    MyPoint minPoint = new MyPoint();
                    setMyPoint(log, minPoint);
                    if (minPoint.getMileage() > maxPointList.get(maxPointList.size()-1).getMileage())
                        minPointList.add(minPoint);
                }
            }else {
                if (weight < minPointList.get(minPointList.size()-1).getWeight()){
                    MyPoint minPoint = minPointList.get(minPointList.size()-1);
                    setMyPoint(log,minPoint);
                }
            }
        }

        for (int i = 0; i < minPointList.size(); i++) {
            VinfoCountOrder vinfoCountOrder = new VinfoCountOrder();
            MyPoint maxPoint = maxPointList.get(i);
            MyPoint minPoint = minPointList.get(i);
            geneCountOrder(car,i,vinfoCountOrder,maxPoint,minPoint);
            vinfoCountOrderList.add(vinfoCountOrder);
        }
        return vinfoCountOrderList;
    }
}
